package com.evil.application.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.evil.application.pojo.entity.ApplicationApplySetting;
import com.evil.common.core.exception.BusinessException;
import com.evil.common.family.enums.RCodeEnum;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.Optional;

/**
 * 应用提交设置表
 *
 * @author liyang
 * @date 2022-08-08 00:00
 */
public interface ApplicationApplySettingMapper extends BaseMapper<ApplicationApplySetting> {

    Optional<ApplicationApplySetting> isExistById(Long id);

    default ApplicationApplySetting findById(Long id) {
        return this.isExistById(id).orElseThrow(() -> new BusinessException(RCodeEnum.APPLICATION_APPLY_SETTING_NOT_EXIST));
    }

    Optional<ApplicationApplySetting> isExistByAppIdAndVersion(@Param("applicationId") Long applicationId,
                                                               @Param("version") Integer version);

    default ApplicationApplySetting findByIdAppIdAndVersion(Long applicationId, Integer version) {
        return this.isExistByAppIdAndVersion(applicationId, version).orElseThrow(() -> new BusinessException(RCodeEnum.APPLICATION_APPLY_SETTING_NOT_EXIST));
    }

    List<ApplicationApplySetting> isExistByAppId(@Param("applicationId") Long applicationId);
}
